package com.amt.olcacon;

import com.amt.olcacon.entity.ImpactData;
import com.amt.olcacon.entity.PivotTable;

import java.util.*;

public class PivotTableDemo {
    public static void main(String[] args) {
        // 1. 准备测试数据（模拟您的数据库数据）
        List<ImpactData> testData = createTestData();
        
        // 2. 创建透视表服务
        PivotTableService service = new PivotTableService();
        
        // 3. 生成透视表
        PivotTable pivotTable = service.createPivotTable(testData);
        
        // 4. 获取简化列名映射
        Map<String, String> columnMapping = service.getSimplifiedColumnNames(pivotTable);
        
        // 5. 显示原始透视表
        System.out.println("=== 原始透视表 ===");
        ConsoleDisplay.displayPivotTable(pivotTable, columnMapping);
        
        // 6. 按GWP100总值排序
        System.out.println("\n=== 按GWP100排序后的透视表 ===");
        PivotTable sortedTable = service.sortRowsByTotal(pivotTable, 
            "Climate change: total (excl. biogenic CO2) - Global warming potential (GWP100)");
        ConsoleDisplay.displayPivotTable(sortedTable, columnMapping);
        
        // 7. 只显示GWP100相关数据
        System.out.println("\n=== 仅显示GWP100相关数据 ===");
        PivotTable filteredTable = service.filterByColumnPattern(pivotTable, "GWP100");
        ConsoleDisplay.displayPivotTable(filteredTable, columnMapping);
        
        // 8. 数据统计
        printStatistics(pivotTable);
    }
    
    private static List<ImpactData> createTestData() {
        List<ImpactData> data = new ArrayList<>();
        
        // 模拟您的数据结构
//        data.add(new ImpactData("电芯", "Climate change: fossil - Global warming potential (GWP100)", 34.122859954833987));
//        data.add(new ImpactData("外壳", "Climate change: fossil - Global warming potential (GWP100)", 7.074894428253174));
//        data.add(new ImpactData("电芯", "Climate change: total (excl. biogenic CO2) - Global warming potential (GWP100)", 34.2232666015625));
//        data.add(new ImpactData("外壳", "Climate change: total (excl. biogenic CO2) - Global warming potential (GWP100)", 7.116755962371826));
//        data.add(new ImpactData("负极材料", "Climate change: fossil - Global warming potential (GWP100)", 16.727298736572267));
//        data.add(new ImpactData("负极材料", "Climate change: total (excl. biogenic CO2) - Global warming potential (GWP100)", 16.768653869628908));
//        // ... 添加更多测试数据
        
        return data;
    }
    
    private static void printStatistics(PivotTable pivotTable) {
        System.out.println("\n=== 数据统计 ===");
        System.out.println("行数（材料/组件种类）: " + pivotTable.getRowCount());
        System.out.println("列数（影响类别）: " + pivotTable.getColumnCount());
        System.out.println("所有材料/组件: " + String.join(", ", pivotTable.getRowNames()));
        System.out.println("所有影响类别: " + String.join(", ", pivotTable.getColumnNames()));
    }
}